<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_merchfuwu/model')->方法名();
*/
namespace jy_merchfuwu;
defined('BY_JYA') or exit('error');
class model extends \plugin{
	public function out_times($store_id,$post=array()) {
		$store=pdo_get('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$store_id));
		$store['onlinetime']=json_decode($store['onlinetime'],true);
		$store['out_pay']=$post['out_pay']?:$store['out_pay'];
		$store['out_pay']=price($store['out_pay']);
		//配送时间
		$days = array(
				0=>date("m-d",time("day")),
				1=>date("m-d",strtotime("+1 day")),
				2=>date("m-d",strtotime("+2 day")), 
				3=>date("m-d",strtotime("+3 day")), 
				4=>date("m-d",strtotime("+4 day")),
				5=>date("m-d",strtotime("+5 day")),
				6=>date("m-d",strtotime("+6 day")),
		);
		$totaytime = strtotime(date('Y-m-d'));
		//配送时间段
		$lasttimebox=0;
		if($post['set_timebox']==1){
			foreach($post['peisong_timebox'] as &$item){
				$start=$daytime.' '.$item['times']['start'];
				$start=strtotime($start);
				$end=$daytime.' '.$item['times']['end'];
				$end=strtotime($end);
				$times[]=array(
					'start' => $item['times']['start'],
					'end' => $item['times']['end'],
					'timestamp' => $end,
					'fee' => 0,
					'timev' =>$item['times']['start'].'~'.$item['times']['end'],
					'out_pay' => $store['out_pay']."元上门费",
				);
				$timestamp[] = $end;
				if($end>$item['yuyue']*60+time()){
					$lasttimebox +=1;
				}
			}
		}else{
			$timestamp = array();
			$daytime=date('Y-m-d');
			if($store['onlinetime']['start']){
				$start=$daytime.' '.$store['onlinetime']['start'];
				$start=strtotime($start);
			}else{
				$start = mktime(8, 0);
			}
			if($store['onlinetime']['end']){
				$end=$daytime.' '.$store['onlinetime']['end'];
				$end=strtotime($end);
			}else{
				$end = mktime(22, 0);
			}
			for($i = $start; $i < $end;) {
					$times[] = array(
						'start' => date('H:i', $i),
						'end' => date('H:i', $i + 1800),
						'timestamp' => $i + 1800,
						'fee' => 0,
						'timev' =>date('H:i', $i).'~'.date('H:i', $i + 1800),
						'out_pay' => $store['out_pay']."元上门费",
					);
					$timestamp[] = $i + 1800;
					$i += 1800;
					if($i + 1800>30*60+time()){
						$lasttimebox +=1;
					}
			}
		}
		$data = array(
			'days' => $days,
			'times' => $times,
			'timestamp' => $timestamp,
			'updatetime' => strtotime(date('Y-m-d')) + 86400,
			'reserve' => 0,
			'lasttimebox' => $lasttimebox,
		);
		return $data;
	}
}
?>